package member;

import includes.Sessions;

import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.List;

import home.HomePage;

import org.apache.wicket.Session;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;


import controllers.Accountability;
import controllers.BKLiquidation;
import controllers.Registered;
import controllers.StudentInformation;

public class MyAccountabilities extends WebPage{

	Reader reader = Resources.getResourceAsReader("sqlMapConfig.xml");
	SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
	
	public MyAccountabilities()throws SQLException, IOException
	{
		add(new BookmarkablePageLink("logoutPage", HomePage.class));
		add(new BookmarkablePageLink("home", MemberHome.class));
		
		
		Form form = new Form("myAccountabilities");
		
		final String studentId = ((Sessions)getSession()).getStudentid();
		
		StudentInformation info = (StudentInformation)sqlMap.queryForObject("StudentInformation.MyInformation" , studentId);
		
		System.out.println(info.getStudent_firstName());
		String name = info.getStudent_firstName() + " " + info.getStudent_middleName() + " " + info.getStudent_lastName();
		form.add(new Label("name", name));
		form.add(new Label("studentId", studentId));
		form.add(new Label("yearlevel", info.getStudent_yearlvl()));
		form.add(new Label("gender", info.getStudent_gender()));
		
		
		
		List<Accountability> list =(List<Accountability>)sqlMap.queryForList("Accountability.getAccountability", studentId);
		
		ListView each = new ListView("each", list) {
			private static final long serialVersionUID = 1L;
			
			protected void populateItem(ListItem item) {
				final Accountability acc = (Accountability) item.getModelObject(); 
	
				item.add(new Label("id", Integer.toString(acc.getAccountability_id())));
				item.add(new Label("desc", acc.getAccountability_desc()));
				item.add(new Label("semester", acc.getSemester()));
				item.add(new Label("schoolyear" , acc.getSchoolyear()));
				item.add(new Label("status", acc.getStatus()));
				
			}
		};
		
		form.add(each);		
		add(form);
	}
}
